<%--
  Created by IntelliJ IDEA.
  User: 乔见东方姑娘
  Date: 2023/9/15
  Time: 9:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page isELIgnored="false" %>
<html>
<head>
    <title>查看所有学生信息</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css"
          integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap-theme.min.css"
          integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"
            integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
            crossorigin="anonymous"></script>
    <script>
        function del(sid){
            const con=confirm("确定要删除id"+sid +"的学生信息吗")
            if(con){
                //当前页面打开url，发送请求
                window.location.href="/deleteStuBySid?sid="+sid
            }
        }
        function update(sid,sname){
            const con=confirm("确定要修改学生编号为: "+sid+"姓名为:"+sname+"的学生信息吗")
            if(con){
                window.location.href="/doUpdateStudent?sid="+sid
            }
        }
    </script>
</head>
<body>
<h1>在这个页面展示学生信息</h1>
<div id="=search">
    <form class="navbar-form navbar-left" role="search" action="/getStudents">
        <div class="form-group">
            <input type="text" class="form-control" name="sname" placeholder="请输入学生姓名">
        </div>
        <button type="submit" class="btn btn-default">Submit</button>
    </form>
</div>
<div>
    <table class="table table-hover">
        <c:choose>
            <c:when test="${not empty sessionScope.stus}">
                <tr>
                    <td>学生编号</td>
                    <td>学生姓名</td>
                    <td>学生性别</td>
                    <td>学生地址</td>
                    <td>操作</td>
                </tr>
                <c:forEach var="stu" items="${sessionScope.stus}">
                    <tr>
                        <td>${stu.sid}</td>
                        <td>${stu.sname}</td>
                        <td>${stu.sex}</td>
                        <td>${stu.address}</td>
                        <td>
                            <div class="glyphicon glyphicon-trash" onclick="del(${stu.sid})"></div>
                        </td>
                        <td>
                            <div class="glyphicon glyphicon-pencil" onclick="update(${stu.sid},'${stu.sname}')"></div>
                        </td>
                    </tr>
                </c:forEach>
            </c:when>
            <c:otherwise>
                <tr>
                    <td colspan="4" style="text-align: center">空空如也</td>
                </tr>
            </c:otherwise>
        </c:choose>
    </table>
</div>
<%--分页--%>
<div id="pagenation">

    <div class="row">
        <div class="col-md-4"></div>
        <div class="col-md-4">
            <nav aria-label="Page navigation" >
                <ul class="pagination pagination-lg">

                    <li><a href="/getStudents?=1">首页</a></li>
                    <li><a href="/getStudents?pageNum=${sessionScope.pageNum-1}">上一页</a></li>
                    <li><a href="#">${sessionScope.pageNum}</a></li>
                    <li><a href="/getStudents?pageNum=${sessionScope.pageNum+1}">下一页</a></li>
                    <li><a href="/getStudents?pageNum=${sessionScope.totalPages}">尾页</a></li>

                </ul>
            </nav>
        </div>
        <div class="col-md-4"></div>
    </div>

</div>
</body>
</html>
